package com.jxwifi.cloud.quickclean.toolkit;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;

import com.idroid.utils.NoDoubleClickListener;
import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.app.AccountMgr;
import com.jxwifi.cloud.quickclean.app.ClientBasicActivity;
import com.jxwifi.cloud.quickclean.app.PasswordLogin;
import com.jxwifi.cloud.quickclean.utils.TitleClient;
import com.jxwifi.cloud.quickclean.utils.ToastUtils;
import com.umeng.analytics.MobclickAgent;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 购买工具包
 */
public class BuyToolKitActivity extends ClientBasicActivity implements BuyToolKitView {

    @Bind(R.id.rv_tool_kit_list)
    RecyclerView mRvToolKitList;
    @Bind(R.id.cb_child)
    CheckBox mCbChild;
    @Bind(R.id.tv_tool_kit_all_price)
    TextView mTvToolKitAllPrice;
    @Bind(R.id.tv_buy_tool_kit_settlement)
    TextView mTvBuyToolKitSettlement;

    private BuyToolKitPresenter mPresenter;
    private View notDataView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_buy_tool_kit);
        ButterKnife.bind(this);
        openEventBus();
        initHead();
        mPresenter = new BuyToolKitPresenter(mBaseContext, this);
        mPresenter.initView();
    }

    private void initHead() {
        TitleClient holder = new TitleClient(ButterKnife.findById(this, R.id.lin_client_title));
        holder.defineTitle("购买工具包");
        holder.defineLeft(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                onBackPressed();
            }
        });
    }

    @OnClick({R.id.cb_child,R.id.tv_tool_kit_all,R.id.tv_buy_tool_kit_settlement})
    void clickCK(View v){
        switch (v.getId()){
            case R.id.cb_child:
            case R.id.tv_tool_kit_all:
                mPresenter.AllCheck();
                break;
            case R.id.tv_buy_tool_kit_settlement:
                mPresenter.Settlement();
                MobclickAgent.onEvent(mBaseContext, "tv_buy_tool_kit_settlement");
                break;
        }
    }

    @Override
    public void oninitData() {
        PasswordLogin.passwordlogin(mBaseContext, TAG, AccountMgr.gettell(mBaseContext), AccountMgr.getpassword(mBaseContext));
        if (PasswordLogin.mIsLogin) {
            mPresenter.initData();
        }
    }

    @Override
    public View getViews() {
        notDataView = getLayoutInflater().inflate(R.layout.null_layout, (ViewGroup) mRvToolKitList.getParent(), false);
        return notDataView;
    }

    @Override
    public void onFailure(int errorCode, String msg) {
        Toast toast = Toast.makeText(mBaseContext, msg, Toast.LENGTH_SHORT);
        ToastUtils.showMyToast(toast, 3000);
    }

    @Override
    public RecyclerView getRvList() {
        return mRvToolKitList;
    }

    @Override
    public CheckBox getChild() {
        return mCbChild;
    }

    @Override
    public TextView getAllPrice() {
        return mTvToolKitAllPrice;
    }

    @Override
    public TextView getSettlement() {
        return mTvBuyToolKitSettlement;
    }
}
